/*
	jGrouse framework
	Copyright 2007 by Denis Riabtchik 
	All rights reserved.
	
	Licensed under modified BSD license. See license.txt for details
*/

/**
	@module jgrouse.widgets.SimpleLayout
	@requires jgrouse.widgets.Layout
*/

jgrouse.module({
	name : 'jgrouse.widgets.SimpleLayout',
	requires : ['jgrouse.widgets.Layout'],
	body : function(embed)
	{
		eval(embed);
		/**
			Simple layout containing widgets that are inserted sequentially. This layout would ignore
			all constraints.
			@class jgrouse.widgets.SimpleLayout
			@extends jgrouse.widgets.Layout
		*/
		jgrouse.define('jgrouse.widgets.SimpleLayout', 'jgrouse.widgets.Layout', function(embed)
		{
			eval(embed);
			
			return {
				/**
					constructor initialize
					@inheritdesc
				*/
				initialize : function()
				{
					_sup(this, arguments);
					this._parentDom = null;
					this._counter = 0;
				},
				
				/**
					@function addWidget
					@inheritdesc
				*/
				addWidget : function(widget, constraint)
				{
					_super(this, 'addWidget', widget, this._counter++);
					if (this._parentDom)
					{
						widget.add(this._parentDom);
					}
				},
				
				/**
					@function render
					@inheritdesc
				*/
				render : function(parentDom)
				{
					this._parentDom = parentDom;
					this.forEach(function(widget)
					{
						widget.add(parentDom);
					});
				},
				
				/**
					@function doParse
					@inheritdesc
				*/
				doParse : function()
				{
					// do nothing
				},
				
				/**
					@function remove
					@inheritdesc
				*/
				remove : function(parentDom)
				{
					this.forEach(function(widget)
					{
						widget.remove(false);
					});
					this._parentDom = null;
					_sup(this, arguments);
				}
			}
		});
	}
	
});
